#ifndef FILERECEIVER_H
#define FILERECEIVER_H

#include "TcpReceiver.h"
#include "FileKey.h"

class FileReceiver : public TcpReceiver
{
	Q_OBJECT

	public:
		FileReceiver();
		FileKey GetKey();
		void SetKey(QHostAddress addr, QString fileName, Mode mode = Rx);

	protected:
		void OnInitialization();
		void OnReadStream(const char *s, int len);

	protected slots:
		void OnDisconnected();

	private:
		void Stop();

	private:
		bool _request;
		long long _size;
		FILE *_fp;
		QString _fileName;
		Mode _mode;
		FileKey _key;

	signals:
		void sigStarted(FileKey key, long long size);
		void sigError(FileKey key, QString errorStr);
		void sigFileReceived(FileKey key, int nbyte);
		void sigComplete(FileKey key);
};

#endif // FILERECEIVER_H
